<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">所属公司</label>
          <template>
              <el-select v-model="query.ownerCompanyId" clearable placeholder="请选择" class="filter-item" @keyup.enter.native="crud.toQuery" filterable >
                <el-option
                  v-for="item in companyData"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </template>
        <label class="el-form-item-label">骑手姓名</label>
        <el-input v-model="query.userName" clearable placeholder="骑手姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">骑手身份证</label>
        <el-input v-model="query.userIdCard" clearable placeholder="骑手身份证" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker
          v-model="query.policyTime"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <crudOperation :permission="permission" />
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" v-if="false" />
        <el-table-column prop="userName" label="骑手姓名" />
        <el-table-column prop="userIdCard" label="骑手身份证" />
        <el-table-column prop="ownerCompanyName" label="所属公司">
          <template slot-scope="scope">
            {{ companyData.filter((item,i)=> { return item.id === scope.row.ownerCompanyId } ).map(item => item.name)[0] }}
          </template>
        </el-table-column>
        <el-table-column prop="createUserName" label="录入人" />
        <el-table-column prop="policyStartTime" label="保单生效时间" />
        <el-table-column prop="policyEntTime" label="保单失效时间" />
        <el-table-column prop="policyStatus" label="在保状态">
          <template slot-scope="scope">
            {{ dict.label.policy_status[scope.row.policyStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="lastUpdateName" label="操作人" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudInsuredUser from '@/api/insurance/user'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'
import { getTopDept } from '@/api/system/dept'

const defaultForm = { id: null, createUserId: null, isDeleted: null, createTime: null, lastUpdateTime: null, lastUpdateId: null, ownerId: null, ownerCompanyId: null, userName: null, userIdCard: null, userMobile: null, policyStartTime: null, policyEntTime: null, policyStatus: null }
export default {
  name: 'InsuredUserHistory',
  components: { pagination, crudOperation, rrOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['policy_status'],
  cruds() {
    return CRUD({ title: '历史人员', url: 'api/insured-user', idField: 'id', sort: 'id,desc', crudMethod: { ...crudInsuredUser },
      optShow: {
        add: false,
        edit: false,
        del: false,
        reset: false,
        download: true
      }
    })
  },
  data() {
    return {
      queryTypeOptions: [
        { key: 'ownerCompanyId', display_name: '所属公司ID' },
        { key: 'userName', display_name: '骑手姓名' },
        { key: 'userIdCard', display_name: '骑手身份证' },
        { key: 'policyStartTime', display_name: '保单生效时间' }
      ],
      companyData: [],
      permission: {
        download: ['admin', 'insured:download']
      }
    }
  },
  created() {
    getTopDept().then(res => {
      this.companyData = res
    })
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }

}
</script>

<style scoped>

</style>
